package com.spring.boot.sample.test2.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.spring.boot.sample.test2.bean.TestPojo;
import com.spring.boot.sample.test2.config.Wisely2Settings;
import com.spring.boot.sample.test2.config.WiselySettings;
import com.spring.boot.sample.test2.service.TestPojoService;

@RestController
public class TestPojoController {

	@Autowired
	private TestPojoService testPojoService;
	
	@Autowired
	private Wisely2Settings wisely2Settings;
	@Autowired
	private WiselySettings wiselySettings;
	
	@RequestMapping("/all")
	public List<TestPojo> queryAll(){
		return testPojoService.queryAll();
	}
	@RequestMapping("/{id}/user")
	public TestPojo getUser(@PathVariable("id") int id){
		return testPojoService.getBykey(id);
	}
	/**
	 * 删除缓存
	 * @param id
	 * @return
	 */
	@RequestMapping("/{id}/delete")
	public String delete(@PathVariable("id")int id){
		testPojoService.deleteFromCache(id);
		return "ok";
	}
	/**
	 * 获取自定义配置
	 * @return
	 */
	@RequestMapping("/getpro")
	public Map<String, Object> getProperties(){
		Map<String,Object> map=new HashMap<String, Object>();
		map.put("applicationp",wisely2Settings.getName()+"--"+wisely2Settings.getGender());
		map.put("newp",wiselySettings.getName()+"--"+wiselySettings.getGender());
		return map;
	}
	
}
